package com.gufe.controller.admin.mmp;

import com.gufe.dto.message.MsgListDTO;
import com.gufe.result.Result;
import com.gufe.service.user.message.MessageService;
import com.gufe.utils.BaseContext;
import com.gufe.vo.message.MsgListVO;
import com.gufe.vo.message.MsgUserListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminMessageController")
@RequestMapping("/admin/mp/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    //获取聊天记录
    @GetMapping("/msgList")
    public Result<List<MsgListVO>> getMsgList(Long senderId){
        Long userId = BaseContext.getCurrentId();
        List<MsgListVO> msgList = messageService.getMsgList(MsgListDTO.builder().userId(userId).chatId(senderId).build());
        return Result.success(msgList);
    }

    //获取好友列表
    @GetMapping("/friendList")
    public Result<MsgUserListVO> getMsgUserList(){
        Long userId = BaseContext.getCurrentId();
        MsgUserListVO msgUserListVO = messageService.getMsgUserList(userId);
        return Result.success(msgUserListVO);
    }

    //清除未读消息
    @DeleteMapping("/cleanUnread")
    public Result<String> cleanUnread(Long receiverId){
        Long userId = BaseContext.getCurrentId();
        messageService.cleanUnread(userId,receiverId);
        return Result.success();
    }
}
